<template>
    <div class="outer">
        <el-row>
            <el-col :span="12" class="left">
                <div class="card" id="c1">
                    <h2>业务数据统计</h2>
                    <div>
                        <div class="item">
                            <h3>住客总数</h3>
                            <div>{{ count.userCount }}</div>
                        </div>
                        <div class="item">
                            <h3>预约总数</h3>
                            <div>{{ count.reserveCount }}</div>
                        </div>
                        <div class="item">
                            <h3>房间总数</h3>
                            <div>{{ count.roomCount }}</div>
                        </div>
                        <div class="item">
                            <h3>套餐总数</h3>
                            <div>{{ count.facilityCount }}</div>
                        </div>
                    </div>
                </div>
            </el-col>
            <el-col :span="12" class="right">
                <div class="card" id="c2">
                    <h2 style="padding-top: 15px;">热门房间预约数据统计</h2>
                    <div class="charts" ref="c2Ref"></div>
                </div>
            </el-col>
        </el-row>
        <el-row>
            <el-col class="bottom">
                <div id="c3" class="card">
                    <h2 style="padding-top: 10px;">本月房间预约情况数据统计</h2>
                    <div class="chartss" ref="c3Ref"></div>
                </div>
            </el-col>
        </el-row>
    </div>

</template>

<style scoped>
.chartss{
    height: 160px;
}
.charts {
    height: 320px;
}

#c1>div>.item>h3 {
    text-align: center;
}

#c1>div>.item>div {
    width: 140px;
    height: 140px;
    /* background-color: aquamarine; */
    box-sizing: border-box;
    border: 20px solid aqua;
    border-radius: 140px;
    text-align: center;
    line-height: 90px;
    font-size: 30px;
}

#c1>div {
    display: flex;
    justify-content: space-around;
    height: 250px;
    margin-top: 30px;
}

.card>h2 {
    font-size: 30px;
    font-weight: normal;
    margin: 0;
    box-sizing: border-box;
    padding-top: 30px;
    text-align: center;
}

.outer {
    height: 100%;
    /* background-color: aliceblue; */
}

.card {
    background-color: #fff;
}

#c1,
#c2 {
    height: 390px;
    border-radius: 10px;
}

#c3 {
    height: 210px;
    border-radius: 10px;
}

.left,
.right,
.bottom {
    box-sizing: border-box;
    padding: 5px;
}
</style>

<script setup>
import { ref, onMounted } from 'vue';
import { getcharts, gettotal,getquxian } from "@/api/charts";
//导入echarts
import * as echarts from "echarts";
// 1.获取要显示图标的dom
let c2Ref;
let c3Ref;
onMounted(async () => {
    // 3.编写配置项
    await search();
    await settotal();
    await getquxianmath();
    // 2.创建echarts实例
    let chart2 = echarts.init(c2Ref);
    let chart3=echarts.init(c3Ref);
    // 4.设置配置项
    chart2.setOption(c2opt.value);
    chart3.setOption(optionss.value);
    

});
//曲线

async function getquxianmath(){
    let resp=await getquxian();
    let data = resp.data;
    //console.log(data);
    let nameArr = [];
    let valueArr = [];
    for (let item of data) {
        nameArr.push(item.name);
        valueArr.push(item.value);
    }
    optionss.value.series[0].data = valueArr;
    optionss.value.xAxis.data = nameArr;
}


let optionss=ref({
    grid: {  
        left: '3%',  
        right: '4%',  
        bottom: '3%', 
        top:'8%', 
        containLabel: true // 确保坐标轴标签不被裁剪  
        // top 可以不设置或设置为其他值，根据需要  
    },  
  xAxis: {
    type: 'category',
    data: []
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: [],
      type: 'line'
    }
  ]
});




//饼
async function settotal() {
    let resp = await gettotal();
   // console.log(resp.data);
    c2opt.value.series[0].data = resp.data;
}

let c2opt = ref({
    tooltip: {
        trigger: 'item'
    },

    series: [
        {
            name: '热门房间预约数据统计',
            type: 'pie',
            radius: ['40%', '70%'],
            center: ['50%', '55%'],
            avoidLabelOverlap: false,
            itemStyle: {
                borderRadius: 10,
                borderColor: '#fff',
                borderWidth: 2
            },
            emphasis: {
                label: {
                    show: true,
                    fontSize: 40,
                    fontWeight: 'bold'
                }
            },
            
            emphasis: {
                label: {
                    show: true,
                    fontSize: 20,
                    fontWeight: 'bold'
                }
            },
            data: [ ]

        }
    ]
});
















async function search() {
    let resp = await getcharts();
    count.value = resp.data[0];
    // console.log(resp.data) 
}
let count = ref({
    userCount: "",
    roomCount: "",
    facilityCount: "",
    reserveCount: ""
});

</script>